//
//  BattlefieldTableViewCell.m
//  LookScore
//
//  Created by wws on 2018/1/18.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#define controlWidth (LSScreenWidth-LSSpaceLeftWidth1*2-20)/3

#import "BattlefieldTableViewCell.h"

@interface BattlefieldTableViewCell(){
    
    UIImageView *_headImageView;
    UILabel  *_nameLab;
    UIButton *_attentionBu;
    UILabel  *_introduceLab;
    UILabel  *_timeLab;
    UIButton *_adressBu;
    UIButton *_browseBu;
    UIButton *_commentBu;
    UIButton *_praiseBu;
}


@end

@implementation BattlefieldTableViewCell


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


+(BattlefieldTableViewCell *)battlefieldTableViewCellWidthTableView:(UITableView *)tableView{
    
    BattlefieldTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[BattlefieldTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addContentView];
    }
    
    return self;
}

-(void)addContentView{
    
    UIImageView *headImageView=[[UIImageView alloc]init];
    headImageView.layer.masksToBounds=YES;
    headImageView.layer.cornerRadius=2;
    [self.contentView addSubview:headImageView];
    headImageView.userInteractionEnabled=YES;
    _headImageView=headImageView; headImageView.sd_layout.leftEqualToView(self.contentView).offset(LSSpaceLeftWidth1).topEqualToView(self.contentView).offset(12).widthIs(30).heightIs(30);
    
    UILabel *nameLab=[[UILabel alloc]init];
    nameLab.font=LSFontSize11;
    nameLab.textColor=LSTitleGrayColor3;
    nameLab.textAlignment=NSTextAlignmentLeft;
    [self.contentView addSubview:nameLab];
    _nameLab=nameLab;
    nameLab.sd_layout.leftSpaceToView(headImageView, 7).centerYEqualToView(headImageView).heightIs(20).autoWidthRatio(6);
    
    UIButton *attentionBu=[[UIButton alloc]init];
    attentionBu.titleLabel.textColor=LSTitleWhiteColor;
    attentionBu.titleLabel.font=LSFontSize10;
    [attentionBu setBackgroundImage:[CommonClass getImageWithBgColor:LSSubColor9dd3cc] forState:UIControlStateNormal];
    [attentionBu setBackgroundImage:[CommonClass getImageWithBgColor:LSSubColor55c4bb] forState:UIControlStateHighlighted];
    attentionBu.selected=NO;
    [attentionBu setTitle:@"+关注" forState:UIControlStateNormal];
    [attentionBu setTitle:@"取消关注" forState:UIControlStateSelected];
    attentionBu.layer.masksToBounds=YES;
    attentionBu.layer.cornerRadius=8;
    [attentionBu addTarget:self action:@selector(attentionEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:attentionBu];
    _attentionBu=attentionBu;
    attentionBu.sd_layout.rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1).centerYEqualToView(headImageView).widthIs(50).heightIs(16);
    
    UILabel *introduceLab=[[UILabel alloc]init];
    introduceLab.font=LSFontSize15;
    introduceLab.textColor=LSTitleGrayColor1;
    introduceLab.textAlignment=NSTextAlignmentLeft;
    introduceLab.numberOfLines=2;
    [self.contentView addSubview:introduceLab];
    _introduceLab=introduceLab;
    introduceLab.sd_layout.leftEqualToView(headImageView).topSpaceToView(headImageView,14).rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1).heightIs(40);
    
    
    UIView *backView=[[UIView alloc]init];
    backView.backgroundColor=LSTitleWhiteColor;
    [self.contentView addSubview:backView];
    backView.sd_layout.leftEqualToView(headImageView).topSpaceToView(introduceLab, 9).rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1).heightIs(80);
    
    for (int i=0; i<3; i++) {
        UIImageView *imageView=[[UIImageView alloc]init];
        imageView.image=[UIImage imageNamed:@"MineHead"];
        [backView addSubview:imageView];
        imageView.sd_layout.leftEqualToView(backView).offset((controlWidth+10)*i).topEqualToView(backView).widthIs(controlWidth).bottomEqualToView(backView);
        
    }
    
    
    UIButton *adressBu=[UIButton new];
    [adressBu setTitleColor:Color(253, 140, 53) forState:UIControlStateNormal];
    adressBu.titleLabel.font=LSFontSize13;
    adressBu.layer.cornerRadius=5;
    adressBu.layer.masksToBounds=YES;
    adressBu.layer.borderColor=Color(253, 140, 53).CGColor;
    adressBu.layer.borderWidth=.5f;
    [self.contentView addSubview:adressBu];
    _adressBu=adressBu;
    adressBu.sd_layout.leftEqualToView(headImageView).topSpaceToView(backView,9).widthIs(60).heightIs(20);
    
    UILabel *timeLab=[[UILabel alloc]init];
    timeLab.font=LSFontSize10;
    timeLab.textColor=LSTitleGrayColor3;
    timeLab.textAlignment=NSTextAlignmentLeft;
    [self.contentView addSubview:timeLab];
    _timeLab=timeLab;
    timeLab.sd_layout.leftSpaceToView(adressBu, 7).centerYEqualToView(adressBu).heightIs(20).autoWidthRatio(5);
    
    UIButton *browseBu=[UIButton new];
    [browseBu setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
    [browseBu setImage:[UIImage imageNamed:@"ChatBrowse"] forState:UIControlStateNormal];
    browseBu.titleLabel.font=LSFontSize10;
    [browseBu setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
    [self.contentView addSubview:browseBu];
    _browseBu=browseBu;
    
    
    UIButton *commentBu=[UIButton new];
    [commentBu setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
    [commentBu setImage:[UIImage imageNamed:@"ChatComment"] forState:UIControlStateNormal];
    commentBu.titleLabel.font=LSFontSize10;
    [commentBu setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
    [self.contentView addSubview:commentBu];
    _commentBu=commentBu;
    
    
    UIButton *praiseBu=[UIButton new];
    [praiseBu setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
    [praiseBu setImage:[UIImage imageNamed:@"ChatPraise"] forState:UIControlStateNormal];
    praiseBu.titleLabel.font=LSFontSize10;
    [praiseBu setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
    [self.contentView addSubview:praiseBu];
    _praiseBu=praiseBu;
    praiseBu.sd_layout.rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1).topEqualToView(adressBu).widthIs(60).heightIs(25);
    
    commentBu.sd_layout.rightSpaceToView(praiseBu, -7).topEqualToView(adressBu).widthIs(60).heightIs(25);
    
    browseBu.sd_layout.rightSpaceToView(commentBu, -7).topSpaceToView(backView,9).widthIs(60).heightIs(25);
    
    //底部的线
    NSInteger lineHeight=8;
    UIView  *bottomLineView=[[UIView alloc]initWithFrame:CGRectMake(0, KBattlefieldCellHeight-lineHeight, LSScreenWidth, lineHeight)];
    bottomLineView.backgroundColor=LSBackGroundColor;
    [self.contentView addSubview:bottomLineView];
    
    [self addfasleData];
    
}


-(void)addfasleData{
    
    _headImageView.image=[UIImage imageNamed:@"MineDefaultHead"];
    
    _nameLab.text=@"金基德";
    
    _introduceLab.text=@"hdferghrtjhgty";
    
    [_adressBu setTitle:@"绿茵沙地" forState:UIControlStateNormal];
    
    _timeLab.text=@"10-31 12:44";
    
    [_browseBu setTitle:@"1992" forState:UIControlStateNormal];
    
    [_commentBu setTitle:@"192" forState:UIControlStateNormal];
    
    [_praiseBu setTitle:@"1000" forState:UIControlStateNormal];
    
}

-(void)attentionEvent:(UIButton *)sender{
    
    sender.selected=!sender.selected;
    
}
@end

